package cn.kgc.tangcco.lamda;

import org.junit.Test;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * @author 李昊哲
 * @Description
 * @create 2020/9/2 上午10:28
 */
public class Lamda4Collection {
    @Test
    public void test01() {
        List<Integer> list = new ArrayList<>() {{
            for (int i = 0; i < 10; i++) {
                add(i);
            }
        }};
        Iterator<Integer> it = list.listIterator();
        while (it.hasNext()) {
            Integer next = it.next();
            System.out.println(next);
        }
    }

    @Test
    public void test02() {
        List<Integer> list = new ArrayList<>() {{
            for (int i = 0; i < 10; i++) {
                add(i);
            }
        }};
        list.forEach((num) -> {
            System.out.println(num);
        });
    }

    @Test
    public void test03() {
        List<Integer> list = new ArrayList<>() {{
            for (int i = 0; i < 10; i++) {
                add(i);
            }
        }};
        list.forEach(num -> System.out.println(num));
    }
}
